package com.ruoyi.project.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.GyFormula;
import com.ruoyi.project.service.IGyFormulaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工艺设计配方表Controller
 * 
 * @author xiangjun
 * @date 2021-12-14
 */
@RestController
@RequestMapping("/gongyi/gy_formula")
public class GyFormulaController extends BaseController
{
    @Autowired
    private IGyFormulaService gyFormulaService;

    /**
     * 查询工艺设计配方表列表
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:list')")
    @GetMapping("/list")
    public TableDataInfo list(GyFormula gyFormula)
    {
        startPage();
        List<GyFormula> list = gyFormulaService.selectGyFormulaList(gyFormula);
        return getDataTable(list);
    }

    /**
     * 导出工艺设计配方表列表
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:export')")
    @Log(title = "工艺设计配方表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GyFormula gyFormula)
    {
        List<GyFormula> list = gyFormulaService.selectGyFormulaList(gyFormula);
        ExcelUtil<GyFormula> util = new ExcelUtil<GyFormula>(GyFormula.class);
        return util.exportExcel(list, "工艺设计配方表数据");
    }

    /**
     * 获取工艺设计配方表详细信息
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gyFormulaService.selectGyFormulaById(id));
    }

    /**
     * 新增工艺设计配方表
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:add')")
    @Log(title = "工艺设计配方表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GyFormula gyFormula)
    {
        return toAjax(gyFormulaService.insertGyFormula(gyFormula));
    }

    /**
     * 修改工艺设计配方表
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:edit')")
    @Log(title = "工艺设计配方表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GyFormula gyFormula)
    {
        return toAjax(gyFormulaService.updateGyFormula(gyFormula));
    }

    /**
     * 删除工艺设计配方表
     */
    @PreAuthorize("@ss.hasPermi('gongyi:gy_formula:remove')")
    @Log(title = "工艺设计配方表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gyFormulaService.deleteGyFormulaByIds(ids));
    }
}
